<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/resource/js/jquery-3.2.1.js"></script>
</head>
<body>
	
	<h1>列表</h1>
	<form action="list" method="post" id="fm">
		
		<input type="hidden" name="pageNum" value="${info.pageNum }" id="pageNum">
		发薪单名称:<input type="text" name="name" value="${paybill.name }">
		发薪单组织:
			<select name="companyId" data-com="${paybill.companyId }" onclick="comp()" >
				<option value="">请选择</option>
			</select>
		发薪单事业:
			<select name="businessId" data-bus="${paybill.businessId }" onclick="busin()" >
				<option value="">请选择</option>
			</select>
		发薪单部门:
		<select name="deptId" data-dept="${paybill.deptId }">
				<option value="">请选择</option>
			</select>
		<input type="submit" value="查询">
	</form>
	<a href="update?id=0">添加</a>
	<table>
		<tr>
			<td><input type="checkbox" onclick="qx(this)">全选</td>
			<td>id</td>
			<td>发薪编号</td>
			<td>发放单名称</td>
			<td>公司</td>
			<td>事业部</td>
			<td>部门</td>
			<td>总金额</td>
			<td>发薪标准文件</td>
			<td>下载</td>
			<td>发薪时间</td>
			<td>操作</td>
		</tr>
		<c:forEach items="${info.list }" var="li">
			<tr>
				<td><input type="checkbox" class="cl" value="${li.id }"></td>
				<td>${li.id }</td>
				<td>${li.code }</td>
				<td>${li.name }</td>
				<td>${li.companyname }</td>
				<td>${li.businessname }</td>
				<td>${li.deptname }</td>
				<td>${li.acount }</td>
				<td><img alt="无法显示" src="${li.bills }" width="50px" height="50px"></td>
				<td><a href="${li.bills }">下载</a> </td>
				<td><fmt:formatDate value="${li.createtime }" pattern="yyyy-MM-dd"/></td>
				<td><a href="update?id=${li.id }">修改</a><a href="javascript:deletes(${li.id })">删除</a></td>
			</tr>
		</c:forEach>
	</table>
	<jsp:include page="/WEB-INF/view/page.jsp"></jsp:include>
	<script type="text/javascript">
		var dataorganization=${organizations};
		function goPage(pageNum){
			$("#pageNum").val(pageNum);
			$("#fm").submit();
		}
		function deletes(id){
			if (confirm("是否确认删除")) {
				alert("删除成功");
				location="deletes?id="+id;
			}else{
				alert("已经取消删除");
			}
		}
		function qx(thiz){
			$(".cl").attr("checked",thiz.checked);
			var pxid = $(".cl").map(function(){
				return this.value;
			}).get().join();
			alert(pxid);
		}
		$(function(){
			$.post(
				"getorganization",
				{},
				function(msg){
					for (var i = 0; i < msg.length; i++) {
						if (msg[i].parentId==0) {
							$("[name='companyId']").append('<option value="'+msg[i].id+'">'+msg[i].name+'</option>');		
						}
					}
					
					$("[name='companyId']").val($("[name='companyId']").data("com"));
					bus();
				},
				"json"
			)
		})
		function bus() {
			var num = $("[name='companyId']").data("com");
			for (var i = 0; i < dataorganization.length; i++) {
				if(dataorganization[i].parentId==num){
					$("[name='businessId']").append('<option value="'+dataorganization[i].id+'">'+dataorganization[i].name+'</option>');
				}
			}
			$("[name='businessId']").val($("[name='businessId']").data("bus"));
			dep();
		}
		function dep(){
			var num = $("[name='businessId']").data("bus");
			for (var i = 0; i < dataorganization.length; i++) {
				if(dataorganization[i].parentId==num){
					$("[name='deptId']").append('<option value="'+dataorganization[i].id+'">'+dataorganization[i].name+'</option>');
				}
			}
			$("[name='deptId']").val($("[name='deptId']").data("dept"));
		}
		function comp(){
			$("[name='businessId'] option:gt(0)").remove();
			var num = $("[name='companyId']").val();
			for (var i = 0; i < dataorganization.length; i++) {
				if(dataorganization[i].parentId==num){
					$("[name='businessId']").append('<option value="'+dataorganization[i].id+'">'+dataorganization[i].name+'</option>');
				}
			}
		}
		function busin(){
			$("[name='deptId'] option:gt(0)").remove();
			var num = $("[name='businessId']").val();
			for (var i = 0; i < dataorganization.length; i++) {
				if(dataorganization[i].parentId==num){
					$("[name='deptId']").append('<option value="'+dataorganization[i].id+'">'+dataorganization[i].name+'</option>');
				}
			}
		}
	</script>
</body>
</html>